home *** CD-ROM | disk | FTP | other *** search
/ Racing Games (Spidla) / zavodni.iso / Fun Racing / src / FRPowerUp.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2003-06-19  |  9.0 KB  |  426 lines

  1.  
  2.  
  3. #include "FRApp.h"
  4.  
  5. bool FRPowerUp::ms_bHideType = false;
  6.  
  7. TERTTIImplementation(FRPowerUp, TEEngineObject);
  8. TERTTIImplementation(FROilPuddle, TEEngineObject);
  9. TERTTIImplementation(FREMPMine, TEEngineObject);
  10. TERTTIImplementation(FREMPRocket, TEEngineObject);
  11.  
  12. FRPowerUp::FRPowerUp(TEVector &rPos)
  13. {
  14.     TEVector Min, Max, Tmp;
  15.     
  16.     m_Center = rPos;
  17.     m_Center.m_fY = 10.0f;
  18.     Tmp = TEVector(5.0f, 5.0f, 5.0f);
  19.     Min = m_Center - Tmp;
  20.     Max = m_Center + Tmp;
  21.     m_pBoundingVolume = new TEAABoundingBox(Min, Max);
  22.     
  23.     m_ulRespawnTime = 0;
  24.     m_lType = TERandM(4)-1;
  25.     UpdateModel();
  26.  
  27.     m_bShadow = ((FRApp*) FRApp::GetApplication())->GetDetails() <= MEDIUM;
  28. }
  29.  
  30. void FRPowerUp::Animate(UInt32 ulDeltaT, TEEngine* pEngine)
  31. {
  32.     if(m_ulRespawnTime == 0)
  33.     {
  34.         m_Rotation.m_fY += ulDeltaT * 0.18f;
  35.     }
  36.     else
  37.     {
  38.         m_ulRespawnTime += ulDeltaT;
  39.  
  40.         if(m_ulRespawnTime > 25000)
  41.         {
  42.             m_ulRespawnTime = 0;
  43.             m_lType = TERandM(4)-1;
  44.             m_bClip = true;
  45.             UpdateModel();
  46.         }
  47.     }
  48. }
  49.  
  50. void FRPowerUp::OnClip(TEEngineObject* pInfluencer)
  51. {
  52.     if(TEIsDerivedFromClass(FRCar, pInfluencer))
  53.     {
  54.         FRCar* pCar = (FRCar*) pInfluencer;
  55.         m_ulRespawnTime = 1;
  56.         SafeDelete(m_pModelRef);
  57.         m_bClip = false;
  58.         pCar->SetPowerUp(m_lType);
  59.     }
  60. }
  61.  
  62. bool FRPowerUp::VolStaticInfluence(UInt32 ulDeltaT, TEEngineObject* pObject)
  63. {
  64.     return Clips(*pObject->GetBoundingVolume());
  65. }
  66.  
  67. void FRPowerUp::UpdateModel(void)
  68. {
  69.     TEString Name;
  70.  
  71.     if(ms_bHideType)
  72.     {
  73.         Name = "question.tmf";
  74.         m_Rotation.m_fX = 0.0f;
  75.         m_bTransparency = true;
  76.     }
  77.     else
  78.     {
  79.         switch(m_lType){
  80.         default:
  81.         case POWERUP_N2O:
  82.             Name = "gasbottle.tmf";
  83.             m_Rotation.m_fX = 0.0f;
  84.             break;
  85.         case POWERUP_ROCKET:
  86.             Name = "rocket.tmf";
  87.             m_Rotation.m_fX = 90.0f;
  88.             break;
  89.         case POWERUP_MINE:
  90.             Name = "mine.tmf";
  91.             m_Rotation.m_fX = 90.0f;
  92.             break;
  93.         case POWERUP_OIL:
  94.             Name = "oilcan.tmf";
  95.             m_Rotation.m_fX = 0.0f;
  96.             break;
  97.         };
  98.  
  99.         m_bTransparency = false;
  100.     }
  101.  
  102.     m_pModelRef = TEModelManager::GetModelManager()->GetModel(Name);
  103.  
  104.     TEAssert(m_pModelRef);
  105. }
  106.  
  107. void FRPowerUp::RenderShadow(TERenderer* pRender, TECamera* pCam,
  108.                                        TELight* pLights, TEShadowMethod DefaultMethod,
  109.                                        bool bMoreThanOneShadow)
  110. {
  111.     TEMatrix3x3 RotY;
  112.     TEVector Forward, Center;
  113.     Float fWidth, fHeight;
  114.  
  115.     if(!m_bShadow || m_ulRespawnTime != 0)
  116.         return;
  117.  
  118.     if(!ms_bHideType)
  119.     {
  120.         switch(m_lType){
  121.         default:
  122.         case POWERUP_N2O:
  123.             fWidth = 5.0f;
  124.             fHeight = 5.0f;
  125.             break;
  126.         case POWERUP_ROCKET:
  127.             fWidth = 3.0f;
  128.             fHeight = 12.0f;
  129.             break;
  130.         case POWERUP_MINE:
  131.             fWidth = 6.0f;
  132.             fHeight = 2.5f;
  133.             break;
  134.         case POWERUP_OIL:
  135.             fWidth = 2.5f;
  136.             fHeight = 5.0f;
  137.             break;
  138.         };
  139.     }
  140.     else
  141.     {
  142.         fWidth = 11.0f;
  143.         fHeight = 11.0f;
  144.     }
  145.     
  146.     Center = m_Center;
  147.     Forward = TEVector(0.0f, 0.0f, 1.0f);
  148.     RotY.YRotationMatrixDeg(m_Rotation.m_fY);
  149.     Forward = Forward * RotY;
  150.  
  151.     pRender->SetAmbient(192, 192, 192);
  152.     TEEngine::GetEngine()->RenderFakeShadow(Forward, Center, fWidth, fHeight);
  153. }
  154.  
  155.  
  156.  
  157. FROilPuddle::FROilPuddle(TEVector &rPos)
  158. {/*
  159.     TEEngine* pEngine = TEEngine::GetEngine();
  160.     TETerrain* pTerrain = pEngine->GetTerrain();
  161.     TEVector Dir = TEVector(0.0f, -100.0f, 0.0f);
  162.     TEClipInfo Info;
  163.  
  164.     m_pDecal = NULL;
  165.  
  166.     if(pEngine->RayClipsInWorld(rPos, Dir, Info))
  167.     {
  168.         TEString Name = "oil";
  169.         TEString Pak = "racing";
  170.         TETextureReference* pRef = TETextureManager::GetTextureManager()->GetTexture(Name, Pak, false);
  171.  
  172.         m_pDecal = new TEParticleMark(Info.Plane.m_Normal, Info.Intersection, 35.0f);
  173.         m_Center = Info.Intersection;
  174.  
  175.         m_pDecal->SetTexture(pRef);
  176.         m_pDecal->SetLifetime(9999999);
  177.         m_pDecal->SetFading(false, 0);
  178.     }
  179.     else m_Center = rPos;
  180.  
  181.     m_pBoundingVolume = new TEBoundingSphere(m_Center, 15.0f);*/
  182.  
  183.     TEVector Normal = TEVector(0.0f, 1.0f, 0.0f);
  184.     TEString Name = "oil";
  185.     TEString Pak = "racing";
  186.     TETextureReference* pRef = TETextureManager::GetTextureManager()->GetTexture(Name, Pak, false);
  187.  
  188.     m_pDecal = NULL;
  189.     m_Center = rPos;
  190.     m_Center.m_fY = 0;
  191.  
  192.     m_pDecal = new TEParticleMark(Normal, m_Center, 35.0f);
  193.     
  194.     m_pDecal->SetTexture(pRef);
  195.     m_pDecal->SetLifetime(9999999);
  196.     m_pDecal->SetFading(false, 0);
  197.  
  198.  
  199.     m_pBoundingVolume = new TEBoundingSphere(m_Center, 15.0f);
  200. }
  201.  
  202. FROilPuddle::~FROilPuddle()
  203. {
  204.     SafeDelete(m_pDecal);
  205. };
  206.  
  207. void FROilPuddle::Render(TERenderer* pRender, TECamera* pCam)
  208. {
  209.     if(m_pDecal == NULL)
  210.         return;
  211.  
  212.     pRender->EnableDecaling();
  213.     
  214.     m_pDecal->Render(pRender, pCam);
  215.  
  216.     pRender->DisableDecaling();
  217. }
  218.  
  219. void FROilPuddle::OnClip(TEEngineObject* pInfluencer)
  220. {
  221.     if(TEIsDerivedFromClass(FRCar, pInfluencer))
  222.     {
  223.         FRCar *pCar = (FRCar*) pInfluencer;
  224.         pCar->OilHit();
  225.     }
  226. }
  227.  
  228. bool FROilPuddle::VolStaticInfluence(UInt32 ulDeltaT, TEEngineObject* pObject)
  229. {
  230.     if(TEIsDerivedFromClass(FRCar, pObject))
  231.         return m_pBoundingVolume->IntersectsVolume(*pObject->GetBoundingVolume());
  232.     else return false;
  233. }
  234.  
  235.  
  236.  
  237. FREMPMine::FREMPMine(TEVector &rPos)
  238. {
  239.     TEOBoundingBox *pOBox = new TEOBoundingBox;
  240.     TEAABoundingBox BBox;
  241.     TEVector Min, Max;
  242.     TEString Name = "mine.tmf";
  243.  
  244.     m_Center = rPos;
  245.     m_bStatic = false;
  246.     m_bApplyGravity = m_bAlignToTerrain = true;
  247.     m_fElasticity = m_fFrictionFactor = 0.0f;
  248.  
  249.     m_ulClipState = 0; 
  250.  
  251.     m_pModelRef = TEModelManager::GetModelManager()->GetModel(Name);
  252.  
  253.     TEAssert(m_pModelRef);
  254.  
  255.     BBox = m_pModelRef->GetModelBBox();
  256.     BBox.GetData(Min, Max);
  257.  
  258.     pOBox->SetData(m_Center, Min, Max, m_Rotation);
  259.  
  260.     m_pBoundingVolume = pOBox;
  261.  
  262.     m_pSound = NULL;
  263. }
  264.  
  265. FREMPMine::~FREMPMine()
  266. {
  267.     SafeDelete(m_pSound);
  268. }
  269.  
  270. void FREMPMine::Animate(UInt32 ulDeltaT, TEEngine* pEngine)
  271. {
  272.  
  273.     if(m_ulClipState > 0 && m_ulClipState <= 500)
  274.     {
  275.         m_ulClipState += ulDeltaT;
  276.  
  277.         if(m_ulClipState > 500)
  278.         {
  279.             TEEngine::GetEngine()->RemoveParticleSystem(m_pPart);
  280.             m_pPart = NULL;
  281.         }
  282.     }
  283. }
  284.  
  285. void FREMPMine::OnClip(TEEngineObject* pInfluencer)
  286. {
  287.     if(TEIsDerivedFromClass(FRCar, pInfluencer))
  288.     {
  289.         TEString Name;
  290.         TEEngine* pEngine = TEEngine::GetEngine();
  291.         TEVector Up = TEVector(0.0f, 1.0f, 0.0f);
  292.         FRCar *pCar = (FRCar*) pInfluencer;
  293.         pCar->EMPHit();
  294.         
  295.         SafeDelete(m_pModelRef);
  296.         SafeDelete(m_pBoundingVolume);
  297.         
  298.         m_Velocity = TEVector(0,0,0);
  299.         m_bClip = false;
  300.         m_bStatic = true;
  301.         m_bApplyGravity = m_bAlignToTerrain = false;
  302.         
  303.         m_ulClipState = 1;
  304.         
  305.         Name = "emp.ogg";
  306.         
  307.         m_pSound = TESoundManager::GetSoundManager()->GetSound(Name);
  308.         TEAssert(m_pSound);
  309.         m_pSound->Play3D(m_Center, m_Velocity, 0, 1.0f);
  310.         
  311.         m_pPart = new TEParticleFX(m_Center, 1, 15.0f, 1.0f, 180, 0, 0, Up, 20, 1500,
  312.             255, 15.0f, false, false);
  313.         m_pPart->SetColor(0, 0, 128);
  314.         pEngine->AddParticleSystem(m_pPart);
  315.     }
  316.     else
  317.     {
  318.         m_bStatic = true;
  319.         m_bApplyGravity = m_bAlignToTerrain = false;
  320.     }
  321. }
  322.  
  323.  
  324.  
  325. FREMPRocket::FREMPRocket(TEVector &rPos, TEVector &rForward, TEVector &rRot)
  326. {
  327.     TEOBoundingBox *pOBox = new TEOBoundingBox;
  328.     TEAABoundingBox BBox;
  329.     TEVector Min, Max;
  330.     TEString Name = "rocket.tmf";
  331.  
  332.     m_Center = rPos;
  333.     m_ParticleDelta = rForward * -7.0f;;
  334.     m_Velocity = rForward * 1000.0f;
  335.     m_Rotation = rRot;
  336.     m_Rotation.m_fX = 90.0f;
  337.     m_bStatic = false;
  338.     m_fElasticity = m_fFrictionFactor = 0.0f;
  339.  
  340.     m_ulClipState = 0; 
  341.  
  342.     m_pModelRef = TEModelManager::GetModelManager()->GetModel(Name);
  343.  
  344.     TEAssert(m_pModelRef);
  345.  
  346.     BBox = m_pModelRef->GetModelBBox();
  347.     BBox.GetData(Min, Max);
  348.  
  349.     pOBox->SetData(m_Center, Min, Max, m_Rotation);
  350.  
  351.     m_pBoundingVolume = pOBox;
  352.  
  353.     Max = m_Center + m_ParticleDelta;
  354.     Min = -rForward;
  355.     m_pPart = new TEParticleFX(Max, 2, 4, 1.3f, 0, 0, 0, Min, 250, 1000,
  356.         255, 1.0f, true, false);
  357.     m_pPart->SetColor(255, 255, 255);
  358.     TEEngine::GetEngine()->AddParticleSystem(m_pPart);
  359.  
  360.     Name = "rocketflight.ogg";
  361.  
  362.     m_pSound = TESoundManager::GetSoundManager()->GetSound(Name);
  363.     TEAssert(m_pSound);
  364.     m_pSound->Play3D(m_Center, m_Velocity, TESOUND_LOOP, 1.0f);
  365. }
  366.  
  367. FREMPRocket::~FREMPRocket()
  368. {
  369.     SafeDelete(m_pSound);
  370. }
  371.  
  372. void FREMPRocket::Animate(UInt32 ulDeltaT, TEEngine* pEngine)
  373. {
  374.     if(m_ulClipState == 0)
  375.     {
  376.         TEVector Tmp = m_Center + m_ParticleDelta;
  377.         m_pPart->MoveToPosition(Tmp);
  378.  
  379.         m_pSound->UpdateProperties(m_Center, m_Velocity);
  380.     }
  381.     else if(m_ulClipState <= 500)
  382.     {
  383.         m_ulClipState += ulDeltaT;
  384.  
  385.         if(m_ulClipState > 500)
  386.         {
  387.             TEEngine::GetEngine()->RemoveParticleSystem(m_pPart);
  388.             m_pPart = NULL;
  389.         }
  390.     }
  391. }
  392.  
  393. void FREMPRocket::OnClip(TEEngineObject* pInfluencer)
  394. {
  395.     TEEngine* pEngine = TEEngine::GetEngine();
  396.     TEString Name;
  397.     
  398.     SafeDelete(m_pSound);
  399.     SafeDelete(m_pModelRef);
  400.     SafeDelete(m_pBoundingVolume);
  401.  
  402.     m_Velocity = TEVector(0,0,0);
  403.     m_bClip = false;
  404.     m_bStatic = true;
  405.  
  406.     Name = "emp.ogg";
  407.  
  408.     m_pSound = TESoundManager::GetSoundManager()->GetSound(Name);
  409.     TEAssert(m_pSound);
  410.     m_pSound->Play3D(m_Center, m_Velocity, 0, 1.0f);
  411.     
  412.     m_ulClipState = 1;
  413.     
  414.     pEngine->RemoveParticleSystem(m_pPart);
  415.     m_pPart = new TEParticleFX(m_Center, 1, 15.0f, 1.0f, 360, 0, 0, m_ParticleDelta, 20, 1500,
  416.         255, 15.0f, false, false);
  417.     m_pPart->SetColor(0, 0, 128);
  418.     pEngine->AddParticleSystem(m_pPart);
  419.  
  420.     if(TEIsDerivedFromClass(FRCar, pInfluencer))
  421.     {
  422.         FRCar *pCar = (FRCar*) pInfluencer;
  423.         pCar->EMPHit();
  424.     }
  425. }
  426.